{% load i18n %}
{% extends "main.html" %}

{% block title %}{{title}} -  
	{% ifequal action "addBlog" %}
		{% trans "Add" %} 
		{% ifequal entrytype "blog"%}{% trans "Blog" %}{% endifequal %}
		{% ifequal entrytype "page"%}{% trans "Page" %}{% endifequal %}
	{% endifequal %}
	{% ifequal action "editBlog" %}
		{% trans "Edit item" %}
	{% endifequal %}
	{% ifequal action "editBlogReaction" %}
		{% trans "Edit reaction" %}
	{% endifequal %}
{% endblock %}

{% block blogcontainer %}

<!-- Skin CSS file -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.6.0/build/assets/skins/sam/skin.css">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.6.0/build/container/assets/skins/sam/container.css">
<script type="text/javascript" src="/jscripts/fckeditor/fckeditor.js"></script>   
<script type="text/javascript" src="/jscripts/fckeditor/text.js"></script>   
<style>
    .yui-skin-sam .yui-toolbar-container .yui-toolbar-editcode span.yui-toolbar-icon {
        background-image: url( /img/html_editor.gif );
        background-position: 0 1px;
        left: 5px;
    }
    .yui-skin-sam .yui-toolbar-container .yui-button-editcode-selected span.yui-toolbar-icon {
        background-image: url( /img/html_editor.gif );
        background-position: 0 1px;
        left: 5px;
    }
    .editor-hidden {
        visibility: hidden;
        top: -9999px;
        left: -9999px;
        position: absolute;
    }
</style>

<div class="yui-g">

<div id="blogview">
     {% if error %}
    <div class="error">
        {{error}}
    </div>
     {% endif %}
    <div>
    <form method=post onsubmit="return parseBlogContent()" id="previewForm">
        <h4>
            {% ifequal action "addBlog" %}
            {% trans "Add" %} {% ifequal entrytype "blog"%}{% trans "Blog" %}{% endifequal %}{% ifequal entrytype "page"%}{% trans "Page" %}{% endifequal %}
            {% endifequal %}
            {% ifequal action "editBlog" %}
            {% trans "Edit item" %}
            {% endifequal %}
            {% ifequal action "editBlogReaction" %}
            {% trans "Edit reaction" %}
            {% endifequal %}
        </h4>
        {% ifnotequal action "editBlogReaction" %}
        <div id="blogtitle">
         <input name=title_input id="title_input" type=text size="60"
               value='{% if blog %}{{blog.title}}{% endif %}'>
            <label for="title_input"><b>{% trans "Title" %}</b>({% trans "required" %})</label>
        </div>
        <div id="blogtags">
         <input type=text size="60" id="tags" name="tags" value="{% if blog %}{{blog.tags_commas}}{% endif %}">
         <label for="tags"><b>{% trans "Tags" %}</b>({% trans "comma separated without space" %}) </label>
        </div>
        {% endifnotequal %}

        {% ifequal action "editBlog"%}
        {% ifequal blog.entrytype "page"%}
        <div id="blogpermalink">
         <input type=text size="60" id="permalink" name="permalink" value="{% if blog %}{{blog.permalink}}{% endif %}">
         <label for="permalink"><b>{% trans "Permalink" %}</b> </label>
        </div>
        {% endifequal %}
        {% endifequal %}

        {% ifequal action "editBlogReaction" %}
        <h2 class="comments-post">{% trans "About the author" %}</h2>
        <div>
            <input id="name_input" name='name_input' type=text size="60" value="{% if blogReaction %}{{blogReaction.user}}{% endif %}">
            <label for="name_input"><b>{% trans "Name" %}</b> ({% trans "required" %})</label>
        </div>
        <div>
            <input id="mail" name="mail" type=text size="60" value="{% if blogReaction %}{{blogReaction.authorEmail}}{% endif %}">
            <label for="mail"><b>{% trans "Mail" %}</b> ({% trans "required" %})</label>
        </div>
        <div>
            <input id="website" name="website" type=text size="60" value="{% if blogReaction %}{{blogReaction.authorWebsite}}{% endif %}">
            <label for="website"><b>{% trans "Website" %}</b></label>
        </div>
        {% endifequal %}

        <div id="blogpost">
        <h2>{% trans "Content" %}</h2>
        <textarea id="text" name="text_input" rows="20" cols="75">
            {% if blog %}{{blog.content}}{% endif %}
            {% if blogReaction %}{{blogReaction.content}}{% endif %}
        </textarea>
        </div>
        
        {% ifequal action "editBlog" %}
        {% if blog %}
        <input name="blogId" type="hidden" value="{{blog.key.id}}">
        {% endif %}
        {% endifequal %}

        {% ifequal action "editBlogReaction" %}
        {% if blogReaction %}
        <input name="blogReactionId" type="hidden" value="{{blogReaction.key.id}}">
        {% endif %}
        {% endifequal %}
        <br>
        {% ifequal action "addBlog" %}
        <input name=submit_preview type=submit value=preview>
        <input type="hidden" name="preview" value="1">
        {% else %}
        <input name=submit_edit type=submit value=submit>
        {% endifequal %}
        <br><br>
    </form>
    </div>
    {% ifequal preview '1' %}
    {% ifnotequal submitted '1' %}
    <script type="text/javascript">
        function parseConfirmContent() {
            var content = document.getElementById('blogcontent').innerHTML;
            document.forms["submitForm"]["text_input"].value = content;
            document.forms["submitForm"]["submitted"].value = "1";
            return true;
        }
    </script>
    <div>
    <form method=post onsubmit="return parseConfirmContent()" id="submitForm">
        <H2 class=date-header>{{blog.date|timezone:BLOG.time_zone_offset|date:"l, F d, Y"}}</H2>
        <DIV class="post">
            <H3 class=post-title>
                <a href="#">{{blog.title}}</a>
            </H3>
            <DIV class=post-body id="blogcontent">
                {{blog.content}}
            </DIV>
            <DIV class=post-footer>
                {% if blog.tags %}
                <p>
                    {% trans "Tags" %}:
                    {% for tag in blog.tags %}
                    <a href="/tag/{{ tag|unquote }}">{{ tag|unquote }}</a> {% if not forloop.last %},{% endif %}
                    {% endfor %}
                </p><br>
                {% endif %}
                <P>
                    <SPAN class=post-author>{% blocktrans with blog.author as b_author %}Posted by {{ b_author }} at{% endblocktrans %} </SPAN>
                   <SPAN class=post-timestamp>
                       <A class=timestamp-link href="#">{{blog.date|timezone:BLOG.time_zone_offset|date:"H:i A"}}</A>
                   </SPAN>
                </P>
                 <br>
            </DIV>
        </DIV>
        <input name=title_input type=hidden value="{{blog.title}}">
        <input name=tags type=hidden value="{{tags}}">
        <input name=text_input type="hidden"/>
        <input name=entrytype type="hidden" value="{{blog.entrytype}}"/>
        <input name=submitted type=hidden value='0'>
        <input name=submit_add type=submit value=submit>
    </form>
    </div>
    {% endifnotequal%}
    {% endifequal%}
</div>
</div>
{% endblock %}
